/*
 * CDynamicEngine.h
 *
 *  Created on: 02.03.2012
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 *
 */

#ifndef CDYNAMICENGINE_H_
#define CDYNAMICENGINE_H_

#include "../TThreadSafeQueue.h"
#include "DynamicEngineMessages.h"
#include "IAnimationPlayer.h"
#include <boost/thread/thread.hpp>

class CDynamicEngine
{
private:
	CDynamicEngine();
	virtual ~CDynamicEngine();

    void ProcessingThreadFunction();

private:
    static const int INCOME_MESSAGE_COUNT = 50;

	static CDynamicEngine* instance;

	volatile bool loopControl;
	boost::thread *processingThread;
	TThreadSafeQueue<IDynamicEngineMessage*> messageQueue;

	IAnimationPlayer* animationPlayer;
	UINT              processingFPS;
private:
	const static UINT FRAME_DURATION_THREASHOLD_PERCENT = 10;

public:

	static CDynamicEngine *GetEngine();
	static void            DeleteEngine();

    bool PushMessage( IDynamicEngineMessage *Message );

    bool StartDynamicEngine( UINT ProcessingFPS );
    void StopDynamicEngine();
};

#endif /* CDYNAMICENGINE_H_ */
